﻿using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MyBlog2.Repository;
using System.Security.Claims;
using System.Threading.Tasks;
using MyBlog2.ViewModels;
using MyBlog2.Models;
using System;
using Microsoft.AspNetCore.Http;

namespace MyBlog2.Areas.Admin.Controllers
{
    
    [Area("Admin")]
    [Authorize]
    public class AdminManageController : Controller
    {
        private readonly IArticleClassifyRepository _articleClassifyRepository;
        private readonly IArticleRepository _articleRepository;
        private readonly IUserRepository _userRepository;

        public AdminManageController(IArticleClassifyRepository articleClassifyRepository,IArticleRepository articleRepository, IUserRepository userRepository)
        {
            this._articleClassifyRepository = articleClassifyRepository;
            this._articleRepository = articleRepository;
            this._userRepository = userRepository;
        }


        /// <summary>
        /// 后台首页
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            if (HttpContext.User.Identity.IsAuthenticated)
            {
                string userName = HttpContext.User.FindFirst(ClaimTypes.Name).Value;
                ViewBag.userName = userName;
            }
            
            return View();
        }


        /// <summary>
        /// 注销
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("Admin/AdminManage/Logout", Name = "Logout")]
        public async Task<IActionResult> Logout()
        {
            await HttpContext.SignOutAsync();
            return Redirect("/Admin/Home/Login");
            
        }

        

        
    }
}